<template>
  <div>
    <el-row type="flex" align="middle" justify="center">
      <el-col :span="12">
      <h3>授权信息录入</h3>
      <el-form :model="formModel" ref="formModel" :rules="rules" label-position="left" label-width="100px">      
        <el-form-item prop="kname" label="用户名称">
          <el-input type="text" v-model="formModel.kname" auto-complete="off" placeholder="" ></el-input>
        </el-form-item>
        <el-form-item prop="mac" label="MAC地址">
          <el-input type="text" v-model="formModel.mac" auto-complete="off" placeholder="" ></el-input>
        </el-form-item>
        <el-form-item prop="cpu" label="CPU序列号">
          <el-input type="text" v-model="formModel.cpu" auto-complete="off" placeholder="" ></el-input>
        </el-form-item>
        <el-form-item prop="boss" label="主板序列号">
          <el-input type="text" v-model="formModel.boss" auto-complete="off" placeholder="" ></el-input>
        </el-form-item>      
        <el-form-item>
          <el-button type="primary" @click="submitClick('formModel')">确定</el-button>
          <el-button @click="resetClick('formModel')">取消</el-button>
        </el-form-item>
      </el-form>
    </el-col>
    </el-row>
  </div>
</template>

<script>

export default {
  name: 'Keyinfo',
  components: {
    
  },
  data() {
    return {
      rules: {
          kname: [
              { required: true, message: '请输入用户名称', trigger: 'blur'}
          ],
          mac: [
              { required: true, message: '请输入MAC地址', trigger: 'blur'}
          ],
          cpu: [
              { required: true, message: '请输入CPU序列号', trigger: 'blur'}
          ],
          boss: [
              { required: true, message: '请输入BOSS序列号', trigger: 'blur'}
          ]
      },
      formModel: {
      }
    }
  },
  methods: {
    resetClick(formName){
        this.$refs[formName].resetFields();
    },
    submitClick(formName) {
        // 表单验证
        this.$refs[formName].validate(valid => {
            if(valid) {
              let postData = this.$qs.stringify({
                kname:this.formModel.kname,
                mac:this.formModel.mac,
                cpu:this.formModel.cpu,
                boss:this.formModel.boss
              });
              this.$ajax({
                method: 'post',
                url: '/saveKey',
                data: postData
              }).then(function (res) {
                let resdata=res.data;
                this.$message({
                  message: resdata.msg,
                  type: 'success'
                });
                console.log(res);
              }.bind(this));
            } else {
              console.log("error submit！")
              return false
            }
        })
    }
  }
}
</script>
